<template>
  <div class="main-box">
    <div class="cell-box" v-if="!type">
      <div class="title">
        用车前
        <span class="car-number">({{ carNumber }}）</span>
      </div>
      <div class="picture" v-viewer="{ movable: false }" v-if="beforeUseCar.length">
        <div class="img-box" v-for="item in beforeUseCar" :key="item">
          <img class="img" :src="item" />
        </div>
      </div>
      <div class="picture" v-else>暂无图片</div>
    </div>
    <div class="cell-box" v-if="!type">
      <div class="title">
        还车前
        <span class="car-number">({{ carNumber }}）</span>
      </div>
      <div class="picture" v-viewer="{ movable: false }" v-if="beforeReturnCar.length">
        <div class="img-box" v-for="item in beforeReturnCar" :key="item">
          <img class="img" :src="item" />
        </div>
      </div>
      <div class="picture" v-else>暂无图片</div>
    </div>
    <div class="cell-box" v-if="type === 'card'">
      <div class="title">
        <span class="car-number">会员信息：{{ name }}({{ carNumber }})</span>
      </div>
      <div class="picture" v-viewer="{ movable: false }" v-if="cardList.length">
        <div class="img-box" v-for="item in cardList" :key="item.imageUrl">
          <img class="img" :src="item.imageUrl" />
          <div class="label">{{ item.label }}</div>
        </div>
      </div>
      <div class="picture" v-else>暂无图片</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      carNumber: '',
      beforeReturnCar: [], // 还车前
      beforeUseCar: [], // 用车前
      cardList: [], // 证件照
      type: '', // 证件照类型
      name: '' // 会员名称
    }
  },
  created() {
    const { id, num, type, name } = this.$route.params
    this.carNumber = num
    this.type = type
    this.name = name
    this.fetchData(type === 'card' ? num : id, type)
  },
  methods: {
    fetchData(id, type) {
      if (type === 'card') {
        this.$api.member
          .fetch('memberList', {
            rows: 1,
            offset: 1,
            phone: id
          })
          .then(res => {
            const { idcardUrl, handCardUrl, driverNumberurl, driverCardCopyUrl } = res.data[0]
            this.cardList = [
              {
                label: '身份证人脸面',
                imageUrl: idcardUrl
              },
              {
                label: '身份证国徽面',
                imageUrl: handCardUrl
              },
              {
                label: '驾驶证正面',
                imageUrl: driverNumberurl
              },
              {
                label: '驾驶证副本',
                imageUrl: driverCardCopyUrl
              }
            ]
          })
      } else {
        this.$api.order.fetch('queryReturnCarImage', { orderId: id }).then(res => {
          const beforeReturnCar = []
          const beforeUseCar = []
          res.forEach(val => {
            const { type, imageUrl } = val
            if (type === 1) {
              beforeReturnCar.push(imageUrl)
            } else {
              beforeUseCar.push(imageUrl)
            }
          })
          this.beforeReturnCar = beforeReturnCar
          this.beforeUseCar = beforeUseCar
        })
      }
    }
  }
}
</script>

<style lang="less" scoped>
.main-box {
  margin: 10px 10px;
  .car-number {
    margin-bottom: 5px;
    font-size: 14px;
    color: @content-color;
  }
  .cell-box {
    padding: 20px 20px;
    margin-bottom: 10px;
    background-color: @white;
    border-radius: 10px;
    .title {
      margin-bottom: 10px;
      font-size: @f20;
      color: @label-color;
    }
    .picture {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      min-height: 100px;
      .img-box {
        position: relative;
        display: flex;
        align-items: center;
        width: 300px;
        height: 300px;
        padding: 10px 10px;
        margin: 0 10px 10px 0;
        background-color: @border-default;
        border-radius: 10px;
      }
      .img {
        width: 100%;
        max-height: 280px;
        border-radius: 10px;
      }
      .label {
        position: absolute;
        bottom: 0;
        left: 0px;
        width: 100%;
        height: 40px;
        line-height: 40px;
        color: @label-color;
        text-align: center;
        background-color: @mask-bg;
        border-radius: 0 0 10px 10px;
      }
    }
  }
}
</style>
